<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template_dialog.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
	</ui:define>
	<ui:define name="content">
		<div class='full-center-content-scroll-noheader'>
			<h:form id="form">
				<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
					<p:commandButton value="是" type="button"
						styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
					<p:commandButton value="否" type="button"
						styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
				</p:confirmDialog>
				<p:growl id="msgs" showDetail="true" />
				<div class="box box-solid with-border">
					<div class="box-header">
						<p:outputLabel value="无关联厂站的保护：" />
						<p:selectBooleanCheckbox
							value="#{protectDevRelationView.withOutSubstation}"
							style="margin-right:15px;">
						</p:selectBooleanCheckbox>
						<p:outputLabel value="无关联一次设备的保护：" />
						<p:selectBooleanCheckbox
							value="#{protectDevRelationView.withOutPrim}"
							style="margin-right:15px;">
						</p:selectBooleanCheckbox>
						<p:outputLabel value="电压等级："/>
						<h:selectOneMenu id="voltageSelected" value="#{protectDevRelationView.selectedVoltage}">
				            <f:selectItem itemLabel="全部" itemValue="0" />
							<f:selectItem itemLabel="500kV" itemValue="500" />
				            <f:selectItem itemLabel="220kV" itemValue="220" />
				            <f:selectItem itemLabel="110kV" itemValue="110" />
						</h:selectOneMenu>
						<p:commandButton value="查询"
							style="margin-left:4px;margin-right:4px" icon="ui-icon-search"
							update=":form:deviceTb dialogForm:editDlg"
							actionListener="#{protectDevRelationView.queryBySubstationName}" />
						<p:commandButton value="重置"
							style="margin-left:4px;margin-right:4px" icon="ui-icon-refresh"
							update="form"
							actionListener="#{protectDevRelationView.reset}" />
						<div class="box-tools pull-right">
							<button  type="button" id="selectButton" title="高级查询" class="btn btn-default"
								onclick="onSelectDivClick();" style="margin-right: 50px;">
								<span id="selectButtonIcon" class="fa fa-caret-down">
									高级查询</span>
							</button>
						</div>
					</div>
					<div class="panel-collapse collapse" id="selectDiv">
						<p:outputLabel value="EMS变电站名:" style="margin-right:4px" />
						<p:autoComplete scrollHeight="400"
							value="#{protectDevRelationView.substationName}"
							completeMethod="#{protectDevRelationView.completeStationNames}">
						</p:autoComplete>
						<p:outputLabel value="保护名称 :"
							style="margin-left:4px;margin-right:4px" />
						<p:inputText value="#{protectDevRelationView.protectedName}" />
					</div>
				</div>
				<p:toolbar id="toolbar">
					<f:facet name="left">
						<p:commandButton id="newProBtn" value="新建保护" icon="ui-icon-plus"
							rendered="#{s:hasPermission(session,'xtsz_dwmx_bxsjmx_bhsb_sbgl_xjbh')}"
							update="dialogForm:createDetail dialogForm:createSaveBtn"
							actionListener="#{protectDevRelationView.createNew}"
							oncomplete="PF('createDlg').show()" />
						<p:commandButton value="编辑" id="editBtn" process=":form:deviceTb"
							update=" dialogForm:editDlg" oncomplete="PF('editDlg').show()"
							icon="ui-icon-pencil" title="编辑"
							disabled="#{protectDevRelationView.selected == null}"
							rendered="#{s:hasPermission(session,'xtsz_dwmx_bxsjmx_bhsb_sbgl_bj')}">
						</p:commandButton>
					</f:facet>
				</p:toolbar>
				<p:dataTable id="deviceTb" var="device" rowKey="#{device.id}" style="height:600px"
					value="#{protectDevRelationView.model}" selection="#{protectDevRelationView.selected}" lazy="true"
					rows="15" paginator="true" paginatorPosition="bottom" emptyMessage="无记录" rowIndexVar="ite"
					paginatorTemplate="{Customization} {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="10,15,20">
					<p:ajax event="rowSelect" update="form:toolbar" />
					<f:facet name="{Customization}">
						<p:outputLabel value="总计：#{protectDevRelationView.model.rowCount} 条纪录" />
				    </f:facet>
				    <p:ajax event="rowSelectRadio" update="form:toolbar" />
					<p:column selectionMode="single" style="width:15px;text-align:center"/>
					<p:column headerText="序号 " style="width:20px">
						<h:outputText value="#{ite+1}" />
					</p:column>
					<p:column headerText="EMS变电站" width="40">
						<h:outputText value="#{device.subName}" />
					</p:column>
					<p:column headerText="保信私有变电站" width="40">
						<h:outputText value="#{device.privateStationName}" />
					</p:column>
					<p:column headerText="保护名称" width="80">
						<h:outputText value="#{device.name}" />
					</p:column>
					<p:column headerText="保护类型" width="50">
						<h:outputText value="#{device.type}" />
					</p:column>
					<p:column headerText="一次设备名称" width="50">
						<h:outputText value="#{device.protectedName}" />
					</p:column>
					<p:column headerText="一次设备类型" width="50">
						<h:outputText value="#{device.protectedType}" />
					</p:column>
					<p:column headerText="保护型号" width="50">
						<h:outputText value="#{device.devType}" />
					</p:column>
					<p:column headerText="厂家" width="50">
						<h:outputText value="#{device.devManufacturer}" />
					</p:column>
				</p:dataTable>
			</h:form>
			<h:form id="dialogForm">
				<p:dialog widgetVar="editDlg" header="保护编辑" modal="true"
					id="editDlg" width="480" height="400">
					<p:growl id="msgs1" showDetail="true" />
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton id="editSaveBtn" value="保存" icon="ui-icon-disk"
								update="editDlg :form:deviceTb :form:msgs :form:toolbar"
								oncomplete="PF('editDlg').hide()"
								actionListener="#{protectDevRelationView.update}" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel id="editDetail" style="width:100%">
						<p:panelGrid
							rendered="#{not empty protectDevRelationView.selected}"
							style="width:100%">
							<p:row>
								<p:column>
									<h:outputText value="保护设备名称：" />
								</p:column>
								<p:column>
									<p:inputText id="equipment_text"
										value="#{protectDevRelationView.selected.name}"
										label="protectedName" style="width:100%" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="变电站：" />
								</p:column>
								<p:column>
									<p:inputText id="equipment_sub"
										value="#{protectDevRelationView.selected.subName}"
										readonly="true" label="subName" style="width:85%" />
									<p:commandButton title="选择变电站" icon="ui-icon-extlink"
										process="@this" style="margin-left:3px;width:10%"
										onclick="eChooseStation();"/>
									<p:remoteCommand name="onEChooseStationReturn" update="equipment_sub msgs1"
										actionListener="#{protectDevRelationView.onSelectorChosenSubstation4Dialog}"/>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备：" />
								</p:column>
								<p:column>
									<p:inputText id="equipment_Name"
										value="#{protectDevRelationView.selected.protectedName}"
										readonly="true" label="equpName" style="width:70%;" />
									<p:commandButton id="trashButton" icon="ui-icon-trash"
										title="清空" process="@this" style="margin-left:3px;width:10%"
										actionListener="#{protectDevRelationView.cleanChooseEquipment}"
										disabled="#{protectDevRelationView.selected.protectedName == null}"
										update="equipment_Name protectEquType">
									</p:commandButton>
									<p:commandButton title="选择一次设备" icon="ui-icon-extlink"
										process="@this" update="selectedStationId" style="margin-left:3px;width:10%"
										oncomplete="editChooseEquipment();"/>
									<p:remoteCommand name="onEditChooseEquipmentReturn" update="equipment_Name protectEquType msgs1 trashButton"
										actionListener="#{protectDevRelationView.onSelectorChosenEquipment4Dialog}"/>
									<h:inputHidden id="selectedStationId" value="#{protectDevRelationView.selected.subId}" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备类型：" />
								</p:column>
								<p:column>
									<p:selectOneMenu id="protectEquType"
										value="#{protectDevRelationView.selected.protectedType}"
										style="width:100%">
										<f:selectItems
											value="#{protectDevRelationView.protectedTypes}"
											var="protectedType" itemLabel="#{protectedType}"
											itemValue="#{protectedType}" />
									</p:selectOneMenu>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="保护型号：" />
								</p:column>
								<p:column>
									<p:autoComplete
										value="#{protectDevRelationView.selected.devType}"
										style="width:100%"
										completeMethod="#{protectDevRelationView.completeDevTypes}"
										scrollHeight="400" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="保护类型：" />
								</p:column>
								<p:column>
									<p:selectOneMenu
										value="#{protectDevRelationView.selected.type}"
										style="width:100%">
										<f:selectItems value="#{protectDevRelationView.types}"
											var="type" itemLabel="#{type}" itemValue="#{type}" />
									</p:selectOneMenu>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="生产厂家：" />
								</p:column>
								<p:column>
									<p:autoComplete scrollHeight="400" dropdown="true"
										value="#{protectDevRelationView.selected.devManufacturer}"
										completeMethod="#{protectDevRelationView.completeDevManufacturer}">
									</p:autoComplete>
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
				<p:dialog widgetVar="createDlg" header="新建保护" modal="true"
					id="createDlg" width="480" height="400">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton id="createSaveBtn" value="保存"
								icon="ui-icon-disk" update="form:deviceTb form:msgs"
								oncomplete="PF('createDlg').hide()"
								actionListener="#{protectDevRelationView.saveNew}" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel id="createDetail" style="width:100%">
						<p:panelGrid
							rendered="#{not empty protectDevRelationView.created}"
							style="width:100%">
							<p:row>
								<p:column>
									<h:outputText value="保护名称" />
								</p:column>
								<p:column>
									<p:inputText label="name"
										value="#{protectDevRelationView.created.name}"
										style="width:100%"></p:inputText>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="保护类型" />
								</p:column>
								<p:column>
									<p:selectOneMenu value="#{protectDevRelationView.created.type}"
										style="width:100%">
										<f:selectItems value="#{protectDevRelationView.types}"
											var="type" itemLabel="#{type}" itemValue="#{type}" />
									</p:selectOneMenu>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="变电站" />
								</p:column>
								<p:column>
									<p:inputText id="equipment_sub2"
										value="#{protectDevRelationView.created.subName}"
										readonly="true" label="subName" style="width:85%" />
									<p:commandButton title="选择变电站" icon="ui-icon-extlink"
										process="@this" style="margin-left:3px;width:10%"
										onclick="cChooseStation();"/>
									<p:remoteCommand name="onCChooseStationReturn" update="equipment_sub2 msgs1"
										actionListener="#{protectDevRelationView.onNewChosenSubstation4Dialog}"/>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备：" />
								</p:column>
								<p:column>
									<p:inputText id="equipment_Name2"
										value="#{protectDevRelationView.created.protectedName}"
										readonly="true" label="equpName" style="width:70%;" />
									<p:commandButton id="trashButton1" icon="ui-icon-trash"
										title="清空" process="@this" style="margin-left:3px;width:10%"
										actionListener="#{protectDevRelationView.cleanChooseEquipment}"
										disabled="#{protectDevRelationView.selected.protectedName == null}"
										update="equipment_Name2 protectEquType2">
									</p:commandButton>
									<p:commandButton title="选择一次设备" icon="ui-icon-extlink"
										process="@this" update="createdStationId" style="margin-left:3px;width:10%"
										oncomplete="cChooseEquipment('#{protectDevRelationView.created.subId}');"/>
									<p:remoteCommand name="onCChooseEquipmentReturn" update="equipment_Name2 protectEquType2 msgs1 trashButton1"
										actionListener="#{protectDevRelationView.onSelectorChosenEquipmentNew4Dialog}"/>
									<h:inputHidden id="createdStationId" value="#{protectDevRelationView.created.subId}" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备类型：" />
								</p:column>
								<p:column>
									<p:selectOneMenu id="protectEquType2"
										value="#{protectDevRelationView.created.protectedType}"
										style="width:100%">
										<f:selectItems
											value="#{protectDevRelationView.protectedTypes}"
											var="protectedType" itemLabel="#{protectedType}"
											itemValue="#{protectedType}" />
									</p:selectOneMenu>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="保护型号:" />
								</p:column>
								<p:column>
									<p:inputText label="devType"
										value="#{protectDevRelationView.created.devType}"
										style="width:100%"></p:inputText>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="生产厂家" />
								</p:column>
								<p:column>
									<p:inputText label="devManufacturer"
										value="#{protectDevRelationView.created.devManufacturer}"
										style="width:100%"></p:inputText>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="pt_id" />
								</p:column>
								<p:column>
									<p:inputText label="pt_id"
										value="#{protectDevRelationView.created.ptId}"
										style="width:100%"></p:inputText>
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
			</h:form>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/plugins/datatables/jquery.dataTables.js"></script>
		<script
			src="/resources/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="/resources/js/tables/mytable.js"></script>
		<script>
			function onSelectDivClick() {
				var div = $('#selectDiv');
				if (div.hasClass('in')) {
					div.collapse('hide');
					$('#selectButtonIcon').removeClass("fa fa-caret-up");
					$('#selectButtonIcon').addClass("fa fa-caret-down");
				} else {
					div.collapse('show');
					$('#selectButtonIcon').removeClass("fa fa-caret-down");
					$('#selectButtonIcon').addClass("fa fa-caret-up");
				}
			}
			var cChooseStationIndex;
			var cChooseEquipmentIndex;
			var eChooseStationIndex;
			var eChooseEquipmentIndex;
			function cChooseStation(){
				//打开页面
				cChooseStationIndex = layer.open({
					  type: 2,
					  maxmin :false,
					  area: ['550px', '462px'],
					  fixed: false, //不固定
					  title:'设备选择器',
					  maxmin: true,
					  content: '/ui/common/equipment_selector_single_layer.xhtml'
					});
			}
			function cChooseEquipment(stationId){
				var params = '';
				var stationId = document.getElementById('dialogForm:createdStationId').value;
				if(stationId){
					params = '?stationId='+stationId;
				}
				//打开页面
				cChooseEquipmentIndex = layer.open({
					  type: 2,
					  maxmin :false,
					  area: ['550px', '462px'],
					  fixed: false, //不固定
					  title:'设备选择器',
					  maxmin: true,
					  content: '/ui/common/equipment_selector_single_layer.xhtml'+params
					});
			}
			function eChooseStation(){
				//打开页面
				eChooseStationIndex = layer.open({
					  type: 2,
					  maxmin :false,
					  area: ['550px', '462px'],
					  fixed: false, //不固定
					  title:'设备选择器',
					  maxmin: true,
					  content: '/ui/common/equipment_selector_single_layer.xhtml'
					});
			}
			function editChooseEquipment(){
				var params = '';
				var stationId = document.getElementById('dialogForm:selectedStationId').value;
				if(stationId){
					params = '?stationId='+stationId;
				}
				//打开页面
				eChooseEquipmentIndex = layer.open({
					  type: 2,
					  maxmin :false,
					  area: ['550px', '462px'],
					  fixed: false, //不固定
					  title:'设备选择器',
					  maxmin: true,
					  content: '/ui/common/equipment_selector_single_layer.xhtml'+ params
					});
			}
			//此方法名不可更改
			function dialogReturn(index,data){
				var params = [];
				data = eval("("+data+")");
				params.push({name:'className',value:data.className},{name:'classPath',value:data.classPath},{name:'data',value:data.data},{name:'type',value:data.type});
				if(index == cChooseStationIndex){
					onCChooseStationReturn(params);
				}else if(index == cChooseEquipmentIndex){
					onCChooseEquipmentReturn(params);
				}else if(index == eChooseStationIndex){
					onEChooseStationReturn(params);
				}else if(index == eChooseEquipmentIndex){
					onEditChooseEquipmentReturn(params);
				}
			}
		</script>
	</ui:define>
</ui:composition>
